//方法一 直接封装
/*function reverseFun(arr){
	for(var i=0;i<arr.length-1;i++){
		for(var j=0;j<arr.length-1-i;j++){
			var temp = arr[j];
			arr[j] = arr[j+1];
			arr[j+1] = temp;
		}
	}
	return arr;
}
var arrTest = ["hello","aa",2,3,4];
console.log(reverseFun(arrTest));*/

//方法二：使用闭包
/*function reverseFun(ar){
	return function(arr){
		for(var i=0;i<arr.length-1;i++){
			for(var j=0;j<arr.length-1-i;j++){
				var temp = arr[j];
				arr[j] = arr[j+1];
				arr[j+1] = temp;
			}
		}
		return arr;
	}(ar);
}
var arrTest = [1,2,3,4];
console.log(reverseFun(arrTest));*/

//方法三：重写reverse()方法
/*Array.prototype.reverse = function(){
	for(var i=0;i<this.length-1;i++){
		for(var j=0;j<this.length-1-i;j++){
			var temp = this[j];
			this[j] = this[j+1];
			this[j+1] = temp;
		}
	}
	return this;
}
var arr = [1,2,3];
console.log(arr.reverse());*/
//方法四：
var arr = [8, 19, 3, 12, 5, 4, 2, 3, 7, 6, 9];

function test3(arr) {
    var lastIndex = arr.length - 1;
    for (var i = 0; i < arr.length / 2; i++) {
        var temp = arr[i];
        arr[i] = arr[lastIndex - i];
        arr[lastIndex - i] = temp;
    }
    return arr;
}
console.log(test3(arr));
